// 数字补零
function patchZero (str) {
  str = isNaN(+str) ? '0' : str
  const prefix = str > 9 ? '' : '0'
  return prefix + str
}
// 根据形如 '9.00' 这样的字符串，计算该时间对应的时间戳
function calcUnixTime (timeStr, zreoUnix) {
  const [hour, minute] = timeStr.split('.')
  return zreoUnix + hour * 3600 * 1000 + minute * 60 * 1000
}
// 将时间戳输出为日期字符串
function calcUnixToDayStr (unix) {
  const time = new Date(unix)
  const Y = time.getFullYear()
  const M = patchZero(time.getMonth() + 1)
  const D = patchZero(time.getDate())
  return `${Y}-${M}-${D}`
}
// 将时间戳输出为时间字符串
function calcUnixToTimeStr (unix) {
  const time = new Date(unix)
  const h = patchZero(time.getHours())
  const m = patchZero(time.getMinutes())
  return `${h}:${m}`
}
// 根据开始时间戳和结束时间戳计算结果并输出为数组(30分钟为间隔)
function calcTimsArr (startUnix, endUinx) {
  const arr = []
  for (let i = startUnix; i <= endUinx; i += 1800000) {
    arr.push(calcUnixToTimeStr(i))
  }
  return assembleArr(arr)
}
// 拼装最终需要的结果
function assembleArr (arr) {
  arr.map((item, index) => {
    index && (arr[index - 1] += ` - ${item}`)
  })
  arr.length -= 1
  return arr
}
// 计算今天的服务时间
function calcTodayTimes (arr, time) {
  const nextHour = patchZero(time.getHours() + 1)
  const startIndex = arr.findIndex(i => i.slice(0, 2) === nextHour)
  return arr.slice(startIndex, arr.length)
}
// 主函数
function main (startTimeStr, endTimeStr) {
  startTimeStr = startTimeStr || '09.00'
  endTimeStr = endTimeStr || '20.00'
  const startUinx = calcUnixTime(startTimeStr, -28800000)
  const endUinx = calcUnixTime(endTimeStr, -28800000)
  const serviceTimsArr = calcTimsArr(startUinx, endUinx)
  const time = new Date()
  const todayTimesArr = calcTodayTimes(serviceTimsArr, time)
  return {
    today: calcUnixToDayStr(+time),
    tomorrow: calcUnixToDayStr(+time + 86400000),
    todayTimesArr,
    tomorrowTimesArr: serviceTimsArr
  }
}
console.log(main('9.00','18:00'))
// 导出主函数
//export default main